using Microsoft.AspNetCore.Mvc;
using JTZY.Model.Stock.Dto;
using JTZY.Model.Stock;
using JTZY.Service.Stock.IStockService;
using JTZY.Admin.WebApi.Filters;
using JTZY.Model.Order.Dto;

//创建时间：2024-12-30
namespace JTZY.Admin.WebApi.Controllers.Stock
{
    /// <summary>
    /// 调仓订单明细表
    /// </summary>
    [Verify]
    [Route("stock/Transferorderitem")]
    public class TransferorderitemController : BaseController
    {
        /// <summary>
        /// 调仓订单明细表接口
        /// </summary>
        private readonly ITransferorderitemService _TransferorderitemService;

        public TransferorderitemController(ITransferorderitemService TransferorderitemService)
        {
            _TransferorderitemService = TransferorderitemService;
        }

        /// <summary>
        /// 查询调仓订单明细表列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "transferorderitem:list")]
        public IActionResult QueryTransferorderitem([FromQuery] TransferorderitemQueryDto parm)
        {
            var response = _TransferorderitemService.GetList(parm);
            return SUCCESS(response);
        }


        /// <summary>
        /// 查询调仓订单明细表详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "transferorderitem:query")]
        public IActionResult GetTransferorderitem(long Id)
        {
            var response = _TransferorderitemService.GetInfo(Id);
            
            var info = response.Adapt<TransferorderitemDto>();
            return SUCCESS(info);
        }


        [HttpGet("getorderproducts")]
        [ActionPermissionFilter(Permission = "transferorderitem:query")]
        public IActionResult GetOrderProducts(string orderId)
        {
            long userId = HttpContext.GetUId();
            var response = _TransferorderitemService.GetInfo(orderId, userId);

            var info = response.Adapt<List<TransferorderitemDto>>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加调仓订单明细表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "transferorderitem:add")]
        [Log(Title = "调仓订单明细表", BusinessType = BusinessType.INSERT)]
        public IActionResult AddTransferorderitem([FromBody] TransferorderitemDto parm)
        {
            var modal = parm.Adapt<Transferorderitem>().ToCreate(HttpContext);

            var response = _TransferorderitemService.AddTransferorderitem(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新调仓订单明细表
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "transferorderitem:edit")]
        [Log(Title = "调仓订单明细表", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateTransferorderitem([FromBody] TransferorderitemDto parm)
        {
            var modal = parm.Adapt<Transferorderitem>().ToUpdate(HttpContext);
            var response = _TransferorderitemService.UpdateTransferorderitem(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除调仓订单明细表
        /// </summary>
        /// <returns></returns>
        [HttpPost("delete/{ids}")]
        [ActionPermissionFilter(Permission = "transferorderitem:delete")]
        [Log(Title = "调仓订单明细表", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteTransferorderitem([FromRoute]string ids)
        {
            var idArr = Tools.SplitAndConvert<long>(ids);

            return ToResponse(_TransferorderitemService.Delete(idArr));
        }

    }
}